package com.education.platform.api.controller.common;


import com.education.platform.api.service.*;

import com.education.platform.api.vo.response.*;

import com.education.platform.common.qiniu.QiNiuService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;


/**
* describe: 通用功能
* @author : tomato
* @date: 2020-06-07 11:38:44.106
**/
@RestController
@Api("文件")
@RequestMapping("file")
@Validated
public class FileController {
	
    private static final Logger LOGGER = LoggerFactory.getLogger(FileController.class);
    

    @Autowired
    private CoursewareService coursewareService;

  @Autowired
  private QiNiuService qiNiuService;
    /**
     * 获取观看链接
     *
     * @param
     * @return
     */
    @ApiOperation(value = "获取文件链接")
    @GetMapping("getFileLink")
    public QiNiuResponseVO getFileLink(@RequestParam @NotNull(message = "文件id不能为null") @ApiParam("文件id") Integer corsewareId) {
        String url= coursewareService.getQiNiuUrl(corsewareId);
        QiNiuResponseVO responseVO = new QiNiuResponseVO();
        responseVO.setLink(url);
        return responseVO;
    }
    /**
     * 获取上传链接
     *
     * @param
     * @return
     */
    @ApiOperation(value = "获取上传文件token")
    @GetMapping("getUploadToken")
    public QiNiuResponseVO getUploadUrl() {
        String url= qiNiuService.getUploadToken();
        QiNiuResponseVO responseVO = new QiNiuResponseVO();
        responseVO.setUploadToken(url);
        return responseVO;
    }



}
